package com.example.springbootsfzy.controller.gengminghui;

import com.example.springbootsfzy.domain.CourseReviews;
import com.example.springbootsfzy.service.gengminghui.CourseReviewsService;
import com.example.springbootsfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courseReviews")
public class CourseReviewsController {
    @Autowired
    private CourseReviewsService courseReviewsService;

    //查询所有评论和用户昵称
    @GetMapping("/selectAll")
    public R selectAll() {
        return R.ok(courseReviewsService.selectAll());
    }

    //通过课程id查询所有评论和用户昵称
    @GetMapping("/selectByCourseId")
    public R selectByCourseId(Integer courseId) {
        return R.ok(courseReviewsService.selectByCourseId(courseId));
    }

    //删除
    @DeleteMapping("/deleteById")
    public R deleteById(Integer id) {
        int i = courseReviewsService.deleteById(id);
        if (i > 0) {
            return R.ok("删除成功");
        } else {
            return R.error("删除失败");
        }
    }

    //添加评论
    @PostMapping("/insert")
    public R insert(@RequestBody CourseReviews courseReviews) {
        int i = courseReviewsService.insert(courseReviews);
        if (i > 0) {
            return R.ok("添加成功");
        } else {
            return R.error("添加失败");
        }
    }
    @PutMapping("/update")
    public R update(@RequestBody CourseReviews courseReviews) {
        int i = courseReviewsService.update(courseReviews);
        if (i > 0) {
            return R.ok("修改成功");
        } else {
            return R.error("修改失败");
        }
    }

    @GetMapping("/selectByConsultantId")
    public R selectByConsultantId(Integer consultantId) {
        return R.ok(courseReviewsService.selectByConsultantId(consultantId));
    }


}
